package com.uenpay.im.ui.old.activity.chat.manage;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aswife.ui.GifDrawable;
import com.aswife.ui.GifImageView;
import com.aswife.ui.MaskImageView;
import com.qiyunxin.android.http.cache.HttpStreamCache;
import com.qiyunxin.android.http.utils.FileUtils;
import com.qiyunxin.android.http.utils.Utils;
import com.qyx.android.message.type.BusinessCradType;
import com.qyx.android.message.type.MsgContentType;
import com.qyx.android.message.type.PacketType;
import com.qyx.android.protocol.QyxMsg;
import com.qyx.android.protocol.QyxMsgView;
import com.qyx.android.weight.utils.QyxWeightImageUtils;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;
import com.uenpay.im.ui.old.activity.OaWebViewActivity;
import com.uenpay.im.ui.old.activity.chat.ActivityHandle;
import com.uenpay.im.ui.old.activity.chat.DownloadFileActivity;
import com.uenpay.im.ui.old.activity.chat.VideoPlayerActivity;
import com.uenpay.im.ui.old.activity.crowdfund.CrowdFundDetailActivity;
import com.uenpay.im.ui.old.activity.funds.FundsManageActivity;
import com.uenpay.im.ui.old.activity.group.InvitJoinGroupDetailActivity;
import com.uenpay.im.ui.old.activity.map.LocationNavigationActivity;
import com.uenpay.im.ui.old.activity.publicnumber.PublicNumberDetailActivity;
import com.uenpay.im.ui.old.activity.transfer.TransferDetailActivity;
import com.uenpay.im.callback.IDownloadListener;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.FileType;
import com.uenpay.im.entities.NewsEntity;
import com.uenpay.im.entities.SendFile;
import com.uenpay.im.entities.chatbean.AttachModel;
import com.uenpay.im.entities.chatbean.MsgAudioModel;
import com.uenpay.im.entities.chatbean.MsgCradModel;
import com.uenpay.im.entities.chatbean.MsgCrowdFundsModel;
import com.uenpay.im.entities.chatbean.MsgCrowdFundsSystemModel;
import com.uenpay.im.entities.chatbean.MsgFileModel;
import com.uenpay.im.entities.chatbean.MsgGifModel;
import com.uenpay.im.entities.chatbean.MsgImageModel;
import com.uenpay.im.entities.chatbean.MsgLocationModel;
import com.uenpay.im.entities.chatbean.MsgRedModel;
import com.uenpay.im.entities.chatbean.MsgRequestVideoChatModel;
import com.uenpay.im.entities.chatbean.MsgTransferModel;
import com.uenpay.im.entities.chatbean.MsgVideoModel;
import com.uenpay.im.view.PictureShowActivity;
import com.qyx.videochat.util.VideoChatResultType;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;

/**
 * @author SL
 * @created 2016-4-22 下午9:00:27
 * @copyRight http://www.qiyunxin.com
 * @function 会话item数据展示
 */
public class ChatItemDataManager {

	/**
	 * 设置系统消息
	 *
	 * @param textView
	 * @param content_json
	 * @param content
	 */
	public static void setSystemTv(TextView textView, String content_json,
			String content) {
		if (textView == null
				|| (TextUtils.isEmpty(content_json) && TextUtils
						.isEmpty(content))) {
			return;
		} else {
			textView.setText(getSystemContent(content_json, content));
		}

	}

	public static String getSystemContent(String content_json, String content) {

		if (!TextUtils.isEmpty(content_json)
				&& content_json.indexOf("content_param") > -1) {
			try {
				JSONObject json = new JSONObject(content_json);
				if (json != null) {
					JSONArray jsonArray = json.optJSONArray("content_param");
					if (jsonArray != null && jsonArray.length() > 0) {
						Object[] objects = new Object[jsonArray.length()];
						for (int i = 0, size = jsonArray.length(); i < size; i++) {
							JSONObject jsonObject = jsonArray.optJSONObject(i);
							if (jsonObject != null) {
								String tempName = jsonObject
										.optString("nickname");
								String tempCustId = jsonObject
										.optString("custid");
								if (!TextUtils.isEmpty(tempCustId)) {
									String tempName1 = IMApplication.config
											.getFriendsRemarkName(tempCustId);
									if (!TextUtils.isEmpty(tempName1)) {
										tempName = tempName1;
									}
									objects[i] = tempName;
								}
							}
						}
						if (objects != null) {
							return MessageFormat.format(content, objects);
						}
					} else {
						return content;
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
			return content;
		} else {
			return content;
		}

	}

	/**
	 * 设置收到的图片
	 *
	 * @param mContext
	 * @param receivedImageHolder
	 * @param message
	 */
	public static void setReceivedImageData(Context mContext,
			ChatItemViewHolder.ReceivedImageViewHolder receivedImageHolder, QyxMsg message) {
		int w = 0;
		int h = 0;
		AttachModel attachModel = null;
		int[] w_h = null;
		if (message.baseContentModel != null
				&& message.baseContentModel.getAttachmentModel() != null) {
			attachModel = (AttachModel) message.baseContentModel
					.getAttachmentModel();
		}
		if (attachModel != null) {
			w_h = QyxWeightImageUtils.getImageWidthAndHeightToTalk(mContext,
					Integer.parseInt(attachModel.getPic_width()),
					Integer.parseInt(attachModel.getPic_height()));
			ViewGroup.LayoutParams ivLinearParams = receivedImageHolder.received_image
					.getLayoutParams();
			ivLinearParams.height = w_h[1];
			ivLinearParams.width = w_h[0];
			receivedImageHolder.received_image.setLayoutParams(ivLinearParams);
			if (!TextUtils.isEmpty(attachModel.getFileLocalPath())) {
				receivedImageHolder.received_image.SetRecyclableUrl("file://"
						+ attachModel.getFileLocalPath(), true);
			} else {
				receivedImageHolder.received_image.SetRecyclableUrl(
						(APIConfiguration.getFileDownloadBySize(
								attachModel.getFileId(),
								attachModel.getFileHash(), w, h)), true);
			}
		}

	}

	/**
	 * 设置收到的语音数据
	 *
	 * @param mQyxMsgView
	 * @param message
	 * @param receivedAudioHolder
	 */
	public static void setReceivedAudioData(QyxMsgView mQyxMsgView,
			QyxMsg message, ChatItemViewHolder.ReceivedAudioViewHolder receivedAudioHolder) {
		if (mQyxMsgView.is_playing) {
			receivedAudioHolder.received_record.startPlay(true);
		} else {
			receivedAudioHolder.received_record.stopPlay(true);
		}

		if (mQyxMsgView.is_loading) {
			receivedAudioHolder.received_read_status.setVisibility(View.GONE);
			receivedAudioHolder.received_loading.setVisibility(View.VISIBLE);
		} else {
			receivedAudioHolder.received_loading.setVisibility(View.INVISIBLE);

			if (message.have_read == 0) {
				receivedAudioHolder.received_read_status
						.setVisibility(View.VISIBLE);
			} else {
				receivedAudioHolder.received_read_status
						.setVisibility(View.GONE);
			}
		}
		MsgAudioModel audioModel = (MsgAudioModel) mQyxMsgView.msg.baseContentModel;
		if (audioModel != null) {
			receivedAudioHolder.receied_duration.setText(audioModel.getSecond()
					+ "'" + "'");
		}

	}

	/**
	 * 接受的文件数据
	 *
	 * @param mContext
	 * @param message
	 * @param mSendFile
	 * @param receivedFileHolder
	 */
	public static void setReceivedFileData(Context mContext, QyxMsg message,
			SendFile mSendFile, ChatItemViewHolder.ReceivedFileViewHolder receivedFileHolder) {
		if (message != null && message.baseContentModel != null
				&& message.baseContentModel.getAttachmentModel() != null) {
			MsgFileModel msgFileModel = (MsgFileModel) message.baseContentModel;
			receivedFileHolder.received_file_type_name.setText(FileType
					.getFileTypeName(msgFileModel.getName()));
			if (TextUtils.isEmpty(msgFileModel.getName())) {
				receivedFileHolder.received_file_name.setText(mContext
						.getResources().getString(R.string.the_file_unkown));
			} else {
				receivedFileHolder.received_file_name.setText(msgFileModel
						.getName());
			}

			if (TextUtils.isEmpty(msgFileModel.getSize())) {
				receivedFileHolder.received_file_size.setText(mContext
						.getResources().getString(R.string.the_file_unkown));
			} else {
				receivedFileHolder.received_file_size.setText(mSendFile
						.getFileSize(msgFileModel.getSize()));
			}
			// 获取附件
			AttachModel attachModel = (AttachModel) msgFileModel
					.getAttachmentModel();
			if (attachModel != null) {
				if (TextUtils.isEmpty(attachModel.getFileLocalPath())) {
					receivedFileHolder.download_received_file_status
							.setText(mContext.getResources().getString(
									R.string.not_download_received_file));
				} else {
					receivedFileHolder.download_received_file_status
							.setText(mContext.getResources().getString(
									R.string.downloaded_received_file));
				}
			}
		}

	}

	/**
	 * 接受的名片
	 *
	 * @param mContext
	 * @param message
	 * @param receivedCradViewHolder
	 */
	public static void setReceivedCradData(Context mContext, QyxMsg message,
			ChatItemViewHolder.ReceivedCradViewHolder receivedCradViewHolder) {
		if (message != null && message.baseContentModel != null) {
			MsgCradModel msgCradModel = (MsgCradModel) message.baseContentModel;
			if (msgCradModel != null) {
				receivedCradViewHolder.received_crad_avatar
						.SetUrl(APIConfiguration.getAvatarUrlNormal(
								msgCradModel.getCustId(), PacketType.PERSONAL));

				if (msgCradModel.getCradType() == BusinessCradType.PERSONAL_CRAD) {
					receivedCradViewHolder.received_crad_type_text
							.setText(mContext.getResources().getString(
									R.string.public_crad));
				} else {
					receivedCradViewHolder.received_crad_type_text
							.setText(mContext.getResources().getString(
									R.string.crad));
				}

				receivedCradViewHolder.received_crad_name_text
						.setText(msgCradModel.getCustName());
			}
		}
	}

	/**
	 * 设置接收到的转账信息
	 *
	 * @param message
	 * @param receivedTransferViewHodler
	 */
	public static void setRecivedTransferData(QyxMsg message,
			ChatItemViewHolder.ReceivedTransferViewHodler receivedTransferViewHodler) {
		if (message == null || receivedTransferViewHodler == null
				|| TextUtils.isEmpty(message.content_json))
			return;
		MsgTransferModel msgTransferModel = (MsgTransferModel) message.baseContentModel;
		if (msgTransferModel != null) {
			receivedTransferViewHodler.received_transfer_amount
					.setText(MessageFormat.format(IMApplication
							.getAppContext().getString(R.string.red_size),
							msgTransferModel.getAmount()));
			if (!TextUtils.isEmpty(msgTransferModel.getMemo())) {
				receivedTransferViewHodler.received_giro_source_tv
						.setText(msgTransferModel.getMemo());
			} else {
				receivedTransferViewHodler.received_giro_source_tv
						.setText(R.string.transfer);
			}
		}
	}

	/**
	 * 设置接受到的众筹数据
	 *
	 * @param message
	 * @param crownFundViewHodler
	 */
	public static void setReceivedCrownFundData(Context mContext,
			QyxMsg message, ChatItemViewHolder.ReceivedCrownFundViewHodler crownFundViewHodler) {
		if (message != null && crownFundViewHodler != null) {
			MsgCrowdFundsModel crowdFundsModel = (MsgCrowdFundsModel) message.baseContentModel;
			if (crowdFundsModel != null) {
				if (!TextUtils.isEmpty(message.content)) {
					crownFundViewHodler.received_crowndfund_memo_tv
							.setText(crowdFundsModel.getContent());
				} else {
					crownFundViewHodler.received_crowndfund_memo_tv
							.setText(R.string.crowdfund_memo);
				}
				crownFundViewHodler.received_crownfund_total_money_tv
						.setText(MessageFormat.format(mContext.getResources()
								.getString(R.string.get_total_money),
								crowdFundsModel.getAmount()));
			}

		}
	}

	/**
	 * 设置众筹系统消息数据
	 *
	 * @param mContext
	 * @param message
	 * @param crowdFundSystemViewHodler
	 */
	public static void setCrowFundSystemData(final Context mContext,
			final QyxMsg message,
			ChatItemViewHolder.ReceivedCrowdFundSystemViewHodler crowdFundSystemViewHodler) {
		if (message == null || crowdFundSystemViewHodler == null
				|| message.baseContentModel == null)
			return;

		final MsgCrowdFundsSystemModel crowdFundsSystemModel = (MsgCrowdFundsSystemModel) message.baseContentModel;
		if (crowdFundsSystemModel != null) {
			setSystemTv(crowdFundSystemViewHodler.system_tv,
					message.content_json, message.content);
			//
			// crowdFundSystemViewHodler.system_tv.setText(crowdFundsSystemModel
			// .getContent());
			int length = crowdFundSystemViewHodler.system_tv.getText()
					.toString().length();
			int color = Color.argb(255, 2, 150, 209);
			SpannableStringBuilder builder = new SpannableStringBuilder(
					crowdFundSystemViewHodler.system_tv.getText().toString());
			ForegroundColorSpan normalSpan = new ForegroundColorSpan(color);
			builder.setSpan(normalSpan, length - 4, length,
					Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			crowdFundSystemViewHodler.system_tv.setText(builder);
		}
		crowdFundSystemViewHodler.system_tv
				.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						Intent intent = new Intent(mContext, CrowdFundDetailActivity.class);
						intent.putExtra("fundid",
								crowdFundsSystemModel.getFundId());
						mContext.startActivity(intent);
					}
				});
	}

	/**
	 * 设置接收邀请加入群聊
	 *
	 * @param mContext
	 * @param message
	 * @param invitJoinGroupViewHodler
	 */
	public static void setReceivedInvitJoinGroupData(Context mContext,
			QyxMsg message,
			ChatItemViewHolder.ReceivedInvitJoinGroupViewHodler invitJoinGroupViewHodler) {
		if (message != null && invitJoinGroupViewHodler != null) {
			// invitJoinGroupViewHodler.received_invitation_join_group_desc
			// .setText(message.content);
			setSystemTv(
					invitJoinGroupViewHodler.received_invitation_join_group_desc,
					message.content_json, message.content);
			if (!TextUtils.isEmpty(message.content_json)) {
				try {
					JSONObject json = new JSONObject(message.content_json);
					if (json != null) {
						if (json.has("chatid")) {
							String chatid = json.optString("chatid");
							invitJoinGroupViewHodler.received_invitation_join_group_avatar
									.SetUrl(APIConfiguration
											.getAvatarUrlNormal(chatid,
													PacketType.GROUP));
						}

					}
				} catch (JSONException e) {
					e.printStackTrace();
				}

			}
		}
	}

	/**
	 * 发送收经费数据
	 *
	 * @param qyxMsg
	 * @param sendReceiveFundsViewHodler
	 */
	public static void setSendReceiveFundsData(Context mContext, QyxMsg qyxMsg,
			ChatItemViewHolder.SendReceiveFundsViewHodler sendReceiveFundsViewHodler) {
		if (qyxMsg == null || sendReceiveFundsViewHodler == null) {
			return;
		} else {
			if (!TextUtils.isEmpty(qyxMsg.content_json)) {
				JSONObject jsonObject;
				try {
					jsonObject = new JSONObject(qyxMsg.content_json);
					if (jsonObject != null && jsonObject.has("amount")) {
						String amount = jsonObject.optString("amount");
						sendReceiveFundsViewHodler.send_receive_funds_amount_tv
								.setText(MessageFormat.format(
										mContext.getResources().getString(
												R.string.red_size), amount));
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}

			}
		}
	}

	/**
	 * 设置经费系统消息
	 *
	 * @param message
	 * @param fundsSystemViewHodler
	 */
	public static void setReceivedFundsSystemInfo(final Context mContext,
			final QyxMsg message,
			ChatItemViewHolder.ReceivedFundsSystemViewHodler fundsSystemViewHodler) {
		if (message == null || fundsSystemViewHodler == null)
			return;
		if (!TextUtils.isEmpty(message.content)) {
			// TODO 设置系统消息
			setSystemTv(fundsSystemViewHodler.system_tv, message.content_json,
					message.content);
			int length = fundsSystemViewHodler.system_tv.getText().toString()
					.length();
			// fundsSystemViewHodler.system_tv.setText(message.content);

			int color = Color.argb(255, 2, 150, 209);
			ForegroundColorSpan normalSpan = new ForegroundColorSpan(color);
			SpannableStringBuilder builder = new SpannableStringBuilder(
					fundsSystemViewHodler.system_tv.getText().toString());
			if (message.msg_content_type == 10003) {
				builder.setSpan(normalSpan, length - 2, length,
						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			} else {
				builder.setSpan(normalSpan, length - 4, length,
						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			}
			fundsSystemViewHodler.system_tv.setText(builder);
			fundsSystemViewHodler.system_tv
					.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View arg0) {
							if (!TextUtils.isEmpty(message.content_json)) {
								try {
									JSONObject jsonObject = new JSONObject(
											message.content_json);
									if (jsonObject != null
											&& jsonObject.has("chatid")) {
										String chatid = jsonObject
												.optString("chatid");
										Intent intent = new Intent(mContext,
												FundsManageActivity.class);
										if (message.msg_content_type == 10001) {
											intent.putExtra("selected_type", 2);
										} else {
											intent.putExtra("selected_type", 1);
										}
										intent.putExtra("chat_id", chatid);
										mContext.startActivity(intent);
									}
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}
						}
					});
		}
	}

	/**
	 * 接收收经费消息
	 *
	 * @param message
	 * @param receivedReceiveFundsViewHodler
	 */
	public static void setReceivedReceiveFundsData(Context mContext,
			QyxMsg message,
			ChatItemViewHolder.ReceivedReceiveFundsViewHodler receivedReceiveFundsViewHodler) {
		if (message == null || receivedReceiveFundsViewHodler == null)
			return;
		if (!TextUtils.isEmpty(message.content_json)) {
			JSONObject jsonObject;
			try {
				jsonObject = new JSONObject(message.content_json);
				if (jsonObject != null && jsonObject.has("amount")) {
					String amount = jsonObject.optString("amount");
					receivedReceiveFundsViewHodler.received_receive_funds_amount
							.setText(MessageFormat.format(mContext
									.getResources()
									.getString(R.string.red_size), amount));
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}

		}

	}

	/**
	 * 接受的视频通话
	 *
	 * @param message
	 * @param receivedVideoChatViewHolder
	 */
	public static void setReceivedVideoChatData(QyxMsg message,
			ChatItemViewHolder.ReceivedVideoChatViewHolder receivedVideoChatViewHolder) {
		if (message == null || receivedVideoChatViewHolder == null)
			return;
		MsgRequestVideoChatModel msgRequestVideoChatModel = (MsgRequestVideoChatModel) message.baseContentModel;
		if (msgRequestVideoChatModel != null) {
			if (msgRequestVideoChatModel.getDurationTime() != 0) {
				// TODO 视频通话正常
				int minute = msgRequestVideoChatModel.getDurationTime() / 60;
				int second = msgRequestVideoChatModel.getDurationTime() % 60;
				String chatTime = "";
				if (minute == 0) {
					chatTime = " 00 : " + second;
				} else {
					chatTime = minute + " : " + second;
				}
				String result = MessageFormat.format(
						IMApplication.getAppContext().getResources()
								.getString(R.string.video_chat_time), chatTime);
				receivedVideoChatViewHolder.received_video_chat_content
						.setText(result);
			} else {
				if (msgRequestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeRefuse) {
					receivedVideoChatViewHolder.received_video_chat_content
							.setText(R.string.rejected_video_chat);
				} else if (msgRequestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeCancelCall) {
					receivedVideoChatViewHolder.received_video_chat_content
							.setText(R.string.other_cancel_call_video_chat);
				} else if (msgRequestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeBusy) {
					receivedVideoChatViewHolder.received_video_chat_content
							.setText(R.string.busy_call_video_chat);
				}
			}
		}

	}


	/**
	 * 接受的视频
	 *
	 * @param message
	 * @param mContext
	 * @param receivedVideoViewHodler
	 */
	public static void setReceivedVideoData(Context mContext, QyxMsg message, ChatItemViewHolder.ReceivedVideoViewHodler receivedVideoViewHodler) {
		// TODO: 2017/2/17
		if (message == null || receivedVideoViewHodler == null) {
			return;
		}
		MsgVideoModel msgVideoModel = (MsgVideoModel) message.baseContentModel;
		if (msgVideoModel != null) {
			AttachModel attachModel = (AttachModel) msgVideoModel.getAttachmentModel();
			if (attachModel != null) {
				int[] w_h = QyxWeightImageUtils.getImageWidthAndHeightToTalk(mContext, msgVideoModel.getScreeHostW(), msgVideoModel.getScreeHostH());
				ViewGroup.LayoutParams ivLinearParams = receivedVideoViewHodler.received_video_first_frame_image
						.getLayoutParams();
				ivLinearParams.height = w_h[1];
				ivLinearParams.width = w_h[0];
				receivedVideoViewHodler.received_video_first_frame_image.setLayoutParams(ivLinearParams);
				if (!TextUtils.isEmpty(msgVideoModel.getScreeHostLocalPath())) {
					receivedVideoViewHodler.received_video_first_frame_image.SetRecyclableUrl("file://"
							+ msgVideoModel.getScreeHostLocalPath(), true);
				} else {
					String url = APIConfiguration.getFileDownloadPath(msgVideoModel.getScreeHostFileId(), msgVideoModel.getScreeHostFileHash());
					receivedVideoViewHodler.received_video_first_frame_image.SetRecyclableUrl(url, true);
				}
			}
		}
	}

	/**
	 * 收到的OA消息
	 *
	 * @param message
	 * @param receivedOAViewHolder
	 */
	public static void setReceivedOAData(QyxMsg message,
			ChatItemViewHolder.ReceivedOAViewHolder receivedOAViewHolder) {
		try {
			JSONObject contentJson = new JSONObject(message.content);
			receivedOAViewHolder.received_oa_content.setText(contentJson
					.optString("content"));
			receivedOAViewHolder.received_oa_title.setText(contentJson
					.optString("title"));
			JSONArray jsonArray = contentJson.optJSONArray("image");
			if (jsonArray != null && jsonArray.length() > 0) {
				JSONObject picJson = jsonArray.optJSONObject(0);
				if (picJson != null) {
					if (picJson.has("fileid") && picJson.has("filehash")) {
						String file_id = picJson.optString("fileid");
						String file_hash = picJson.optString("filehash");
						receivedOAViewHolder.received_oa_iv
								.SetUrl(APIConfiguration.getFileDownloadPath(
										file_id, file_hash));
					}
				}
			}
			if (message.msg_content_type == MsgContentType.OA_APPROVAL) {
				receivedOAViewHolder.received_oa_type
						.setText(R.string.approval);
			} else if (message.msg_content_type == MsgContentType.OA_REIMBURSEMENT) {
				receivedOAViewHolder.received_oa_type
						.setText(R.string.reimbursement);
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 收到的oa通知
	 *
	 * @param message
	 * @param receivedOANoticeViewHolder
	 */
	public static void setReceivedOANoticeData(QyxMsg message,
			ChatItemViewHolder.ReceivedOANoticeViewHolder receivedOANoticeViewHolder) {
		receivedOANoticeViewHolder.received_oa_notice_type
				.setText(R.string.notice);
		try {
			JSONObject noticeJson = new JSONObject(message.content);
			if (noticeJson != null) {
				if (noticeJson.has("content")) {
					receivedOANoticeViewHolder.received_oa_notice_content
							.setText(noticeJson.optString("content"));
					receivedOANoticeViewHolder.received_oa_notice_title
							.setText(noticeJson.optString("title"));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 收到的oa任务
	 *
	 * @param mContext
	 * @param message
	 * @param receivedOATaskViewHolder
	 */
	public static void setReceivedOaTaskData(Context mContext, QyxMsg message,
			ChatItemViewHolder.ReceivedOATaskViewHolder receivedOATaskViewHolder) {
		receivedOATaskViewHolder.received_task_type.setText(R.string.task);
		try {
			JSONObject taskJson = new JSONObject(message.content);
			if (taskJson != null) {
				if (taskJson.has("content")) {
					receivedOATaskViewHolder.received_task_content
							.setText(taskJson.optString("content"));
				}
				if (taskJson.has("title")) {
					receivedOATaskViewHolder.received_task_title
							.setText(taskJson.optString("title"));
				}
				if (taskJson.has("starttime")) {
					receivedOATaskViewHolder.received_task_start_date
							.setText(taskJson.optString("starttime"));
				}
				if (taskJson.has("endtime")) {
					receivedOATaskViewHolder.received_task_end_date
							.setText(taskJson.optString("endtime"));
				}
				if (taskJson.has("priority")) {
					int priority = taskJson.optInt("priority");
					if (priority == 1) {
						receivedOATaskViewHolder.received_task_grade
								.setText(R.string.task_normal);
						receivedOATaskViewHolder.received_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_main_color_normal));
					} else if (priority == 2) {
						receivedOATaskViewHolder.received_task_grade
								.setText(R.string.task_important);
						receivedOATaskViewHolder.received_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_blue_dark));
					} else if (priority == 3) {
						receivedOATaskViewHolder.received_task_grade
								.setText(R.string.task_urgent);
						receivedOATaskViewHolder.received_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_red));
					} else if (priority == 4) {
						receivedOATaskViewHolder.received_task_grade
								.setText(R.string.task_urgent_important);
						receivedOATaskViewHolder.received_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_red));
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送的图片
	 *
	 * @param mContext
	 * @param mQyxMsgView
	 * @param message
	 * @param sendImageHolder
	 */
	public static void setSendImageData(Context mContext,
			QyxMsgView mQyxMsgView, QyxMsg message,
			ChatItemViewHolder.SendImageViewHolder sendImageHolder) {
		sendImageHolder.group.setTag(mQyxMsgView);
		AttachModel attachModel = null;
		// int[] w_h =
		// QyxWeightImageUtils.getImageWidthAndHeightToTalk(mContext,
		// Integer.parseInt(message.pic_width),
		// Integer.parseInt(message.pic_height));
		int[] w_h = null;
		if (message.baseContentModel != null
				&& message.baseContentModel.getAttachmentModel() != null) {
			attachModel = (AttachModel) message.baseContentModel
					.getAttachmentModel();
		}
		if (attachModel != null) {
			w_h = QyxWeightImageUtils.getImageWidthAndHeightToTalk(mContext,
					Integer.parseInt(attachModel.getPic_width()),
					Integer.parseInt(attachModel.getPic_height()));
			ViewGroup.LayoutParams ivLinearParams = sendImageHolder.send_image
					.getLayoutParams();
			ivLinearParams.height = w_h[1];
			ivLinearParams.width = w_h[0];
			sendImageHolder.send_image.setLayoutParams(ivLinearParams);
			if (!TextUtils.isEmpty(attachModel.getFileLocalPath())) {
				sendImageHolder.send_image.SetRecyclableUrl("file://"
						+ attachModel.getFileLocalPath(), true);
			} else {
				String url = APIConfiguration.getFileDownloadPath(
						attachModel.getFileId(), attachModel.getFileHash());
				sendImageHolder.send_image.SetRecyclableUrl(url, true);
			}

		}

	}

	/**
	 * 发送的语音
	 *
	 * @param mQyxMsgView
	 * @param message
	 * @param sendAudioHolder
	 */
	public static void setSendAudio(QyxMsgView mQyxMsgView, QyxMsg message,
			ChatItemViewHolder.SendAudioViewHolder sendAudioHolder) {
		if (mQyxMsgView.is_playing) {
			sendAudioHolder.send_record.startPlay(false);
		} else {
			sendAudioHolder.send_record.stopPlay(false);
			// sendAudioHolder.send_record.imageView
			// .setBackgroundResource(R.drawable.ic_send_record);
		}
		MsgAudioModel msgAudioModel = (MsgAudioModel) message.baseContentModel;
		if (msgAudioModel != null) {
			sendAudioHolder.send_duration.setText(msgAudioModel.getSecond()
					+ "'" + "'");
		}

	}

	/**
	 * 发送的文件
	 *
	 * @param mContext
	 * @param message
	 * @param mSendFile
	 * @param sendFileHolder
	 */
	public static void setSendFileData(Context mContext, QyxMsg message,
			SendFile mSendFile, ChatItemViewHolder.SendFileViewHolder sendFileHolder) {

		MsgFileModel msgFileModel = (MsgFileModel) message.baseContentModel;
		if (msgFileModel != null) {
			sendFileHolder.send_file_name.setText(msgFileModel.getName());
			sendFileHolder.send_file_size.setText(mSendFile
					.getFileSize(msgFileModel.getSize()));
			// 获取后缀名显示
			sendFileHolder.send_file_type_name.setText(FileType
					.getFileTypeName(msgFileModel.getName()));

			AttachModel attachModel = (AttachModel) msgFileModel
					.getAttachmentModel();
			if (attachModel != null) {
				if (TextUtils.isEmpty(attachModel.getFileId())
						|| TextUtils.isEmpty(attachModel.getFileHash())) {
					sendFileHolder.send_file_status.setText(mContext
							.getResources().getString(
									R.string.not_upload_send_file));
				} else {
					sendFileHolder.send_file_status.setText(mContext
							.getResources().getString(
									R.string.uploaded_send_file));
				}
			}
		}

		// sendFileHolder.send_file_size.setText(message.file_size);

	}

	/**
	 * 发送的名片
	 *
	 * @param mContext
	 * @param message
	 * @param sendCradViewHolder
	 */
	public static void setSendCradData(Context mContext, QyxMsg message,
			ChatItemViewHolder.SendCradViewHolder sendCradViewHolder) {
		MsgCradModel msgCradModel = null;
		if (message.baseContentModel != null) {
			msgCradModel = (MsgCradModel) message.baseContentModel;
		}
		if (msgCradModel == null)
			return;
		sendCradViewHolder.send_crad_avatar.SetUrl(APIConfiguration
				.getAvatarUrlNormal(msgCradModel.getCustId(),
						PacketType.PERSONAL));
		sendCradViewHolder.send_crad_name_text.setText(msgCradModel
				.getCustName());
		if (msgCradModel.getCradType() == BusinessCradType.PUBLIC_NUM_CRAD) {
			sendCradViewHolder.send_crad_type_text.setText(mContext
					.getResources().getString(R.string.public_crad));
		} else {
			sendCradViewHolder.send_crad_type_text.setText(mContext
					.getResources().getString(R.string.crad));
		}
	}

	/**
	 * 设置发送的转账信息
	 *
	 * @param message
	 * @param sendTransferViewHolder
	 */
	public static void setSendTransferData(QyxMsg message,
			ChatItemViewHolder.SendTransferViewHolder sendTransferViewHolder) {
		if (message == null || sendTransferViewHolder == null
				|| TextUtils.isEmpty(message.content_json))
			return;
		MsgTransferModel msgTransferModel = (MsgTransferModel) message.baseContentModel;
		if (msgTransferModel != null) {
			if (!TextUtils.isEmpty(msgTransferModel.getAmount())) {
				sendTransferViewHolder.send_transfer_amount_tv
						.setText(MessageFormat.format(IMApplication
								.getAppContext().getString(R.string.red_size),
								msgTransferModel.getAmount()));
			}
			if (!TextUtils.isEmpty(msgTransferModel.getMemo())) {
				if (!TextUtils.isEmpty(msgTransferModel.getMemo()))
					sendTransferViewHolder.send_giro_source_tv
							.setText(msgTransferModel.getMemo());
				else {
					sendTransferViewHolder.send_giro_source_tv
							.setText(R.string.transfer);
				}
			}
		}

	}

	/**
	 * 设置收到的邀请加入群聊数据
	 *
	 * @param message
	 * @param invitJoinGroupViewHodler
	 */
	public static void setSendInvitJoinGroupData(QyxMsg message,
			ChatItemViewHolder.SendInvitJoinGroupViewHodler invitJoinGroupViewHodler) {

		if (message != null && invitJoinGroupViewHodler != null) {
			// invitJoinGroupViewHodler.send_invi_join_group_desc
			// .setText(message.content);
			setSystemTv(invitJoinGroupViewHodler.send_invi_join_group_desc,
					message.content_json, message.content);
			if (!TextUtils.isEmpty(message.content_json)) {
				try {
					JSONObject json = new JSONObject(message.content_json);
					if (json != null) {
						if (json.has("chatid")) {
							String chatid = json.optString("chatid");
							invitJoinGroupViewHodler.send_invi_join_group_avatar
									.SetUrl(APIConfiguration
											.getAvatarUrlNormal(chatid,
													PacketType.GROUP));
						}

					}
				} catch (JSONException e) {
					e.printStackTrace();
				}

			}
		}

	}

	/**
	 * 设置发送众筹数据(江湖救急)
	 *
	 * @param message
	 * @param crownFundViewHodler
	 */
	public static void setSendCrownFundData(Context mContext, QyxMsg message,
			ChatItemViewHolder.SendCrownFundViewHodler crownFundViewHodler) {
		if (message != null && crownFundViewHodler != null) {
			MsgCrowdFundsModel crowdFundsModel = (MsgCrowdFundsModel) message.baseContentModel;
			if (crowdFundsModel != null) {
				if (!TextUtils.isEmpty(message.content)) {
					crownFundViewHodler.send_crowndfund_memo_tv
							.setText(crowdFundsModel.getContent());
				} else {
					crownFundViewHodler.send_crowndfund_memo_tv
							.setText(R.string.crowdfund_memo);
				}
				crownFundViewHodler.send_crownfund_total_money_tv
						.setText(MessageFormat.format(mContext.getResources()
								.getString(R.string.get_total_money),
								crowdFundsModel.getAmount()));
			}

		}
	}

	/**
	 * 发送的视频聊天
	 *
	 * @param message
	 * @param sendVideoChatViewHolder
	 */
	public static void setSendVideoData(QyxMsg message,
			ChatItemViewHolder.SendVideoChatViewHolder sendVideoChatViewHolder) {
		if (message == null || sendVideoChatViewHolder == null)
			return;

		MsgRequestVideoChatModel requestVideoChatModel = (MsgRequestVideoChatModel) message.baseContentModel;
		if (requestVideoChatModel != null) {
			if (requestVideoChatModel.getDurationTime() != 0) {
				// TODO 视频通话正常
				int minute = requestVideoChatModel.getDurationTime() / 60;
				int second = requestVideoChatModel.getDurationTime() % 60;
				String chatTime = "";
				if (minute == 0) {
					chatTime = " 00 : " + second;
				} else {
					chatTime = minute + " : " + second;
				}
				String result = MessageFormat.format(
						IMApplication.getAppContext().getResources()
								.getString(R.string.video_chat_time), chatTime);
				sendVideoChatViewHolder.send_video_chat_content.setText(result);
			} else {
				/** 视频通话结果 **/
				if (requestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeRefuse) {
					sendVideoChatViewHolder.send_video_chat_content
							.setText(R.string.other_side_has_refused_video_chat);
				} else if (requestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeCancelCall) {
					sendVideoChatViewHolder.send_video_chat_content
							.setText(R.string.cancel_call_video_chat);
				} else if (requestVideoChatModel.getVideoChatResultType() == VideoChatResultType.VideoChatResultTypeBusy) {
					sendVideoChatViewHolder.send_video_chat_content
							.setText(R.string.busy_line_other_side_call_video_chat);
				}
			}
		}

	}


	/**
	 * 发送的视频数据
	 *
	 * @param message
	 * @param sendVideoViewHolder
	 */
	public static void sendVideoData(Context mContext, QyxMsg message, ChatItemViewHolder.SendVideoViewHolder sendVideoViewHolder) {
		if (message == null || sendVideoViewHolder == null) {
			return;
		}
		MsgVideoModel msgVideoModel = (MsgVideoModel) message.baseContentModel;
		if (msgVideoModel != null) {
			AttachModel attachModel = (AttachModel) msgVideoModel.getAttachmentModel();
			if (attachModel != null && !TextUtils.isEmpty(attachModel.getFileLocalPath())) {
				int[] w_h = QyxWeightImageUtils.getImageWidthAndHeightToTalk(mContext, msgVideoModel.getScreeHostW(), msgVideoModel.getScreeHostH());
				ViewGroup.LayoutParams ivLinearParams = sendVideoViewHolder.send_video_first_frame_image
						.getLayoutParams();
				ivLinearParams.height = w_h[1];
				ivLinearParams.width = w_h[0];
				sendVideoViewHolder.send_video_first_frame_image.setLayoutParams(ivLinearParams);
				if (!TextUtils.isEmpty(msgVideoModel.getScreeHostLocalPath())) {
					sendVideoViewHolder.send_video_first_frame_image.SetRecyclableUrl("file://"
							+ msgVideoModel.getScreeHostLocalPath(), true);
				} else {
					String url = APIConfiguration.getFileDownloadPath(msgVideoModel.getScreeHostFileId(), msgVideoModel.getScreeHostFileHash());
					sendVideoViewHolder.send_video_first_frame_image.SetRecyclableUrl(url, true);
				}
			}
		}
	}

	/**
	 * 发送的OA类型消息
	 *
	 * @param message
	 * @param sendOAViewHolder
	 */
	public static void setSendOAData(QyxMsg message,
			ChatItemViewHolder.SendOAViewHolder sendOAViewHolder) {
		try {
			/** OA类型消息 **/
			JSONObject contentJson = new JSONObject(message.content);
			sendOAViewHolder.send_oa_content.setText(contentJson
					.optString("content"));
			sendOAViewHolder.send_oa_title.setText(contentJson
					.optString("title"));
			JSONArray jsonArray = contentJson.optJSONArray("image");
			if (jsonArray != null && jsonArray.length() > 0) {
				JSONObject picJson = jsonArray.optJSONObject(0);
				if (picJson != null) {
					if (picJson.has("fileid") && picJson.has("filehash")) {
						String file_id = picJson.optString("fileid");
						String file_hash = picJson.optString("filehash");
						sendOAViewHolder.send_oa_iv.SetUrl(APIConfiguration
								.getFileDownloadPath(file_id, file_hash));
					}
				}
			}
			if (message.msg_content_type == MsgContentType.OA_APPROVAL) {
				sendOAViewHolder.send_oa_type.setText(R.string.approval);
			} else if (message.msg_content_type == MsgContentType.OA_REIMBURSEMENT) {
				sendOAViewHolder.send_oa_type.setText(R.string.reimbursement);
			}

		} catch (JSONException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 发送的OA通知消息
	 *
	 * @param message
	 * @param sendOANoticeViewHolder
	 */
	public static void setSendOANoticeData(QyxMsg message,
			ChatItemViewHolder.SendOANoticeViewHolder sendOANoticeViewHolder) {
		sendOANoticeViewHolder.send_oa_notice_type.setText(R.string.notice);
		try {
			JSONObject noticeJson = new JSONObject(message.content);
			if (noticeJson != null) {
				if (noticeJson.has("content")) {
					sendOANoticeViewHolder.send_oa_notice_content
							.setText(noticeJson.optString("content"));
					sendOANoticeViewHolder.send_oa_notice_title
							.setText(noticeJson.optString("title"));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 发送OA任务消息
	 *
	 * @param mContext
	 * @param message
	 * @param sendOATaskViewHolder
	 */
	public static void setSendOATaskData(Context mContext, QyxMsg message,
			ChatItemViewHolder.SendOATaskViewHolder sendOATaskViewHolder) {
		sendOATaskViewHolder.send_task_type.setText(R.string.task);
		try {
			JSONObject taskJson = new JSONObject(message.content);
			if (taskJson != null) {
				if (taskJson.has("content")) {
					sendOATaskViewHolder.send_task_content.setText(taskJson
							.optString("content"));
				}
				if (taskJson.has("title")) {
					sendOATaskViewHolder.send_task_title.setText(taskJson
							.optString("title"));
				}
				if (taskJson.has("starttime")) {
					sendOATaskViewHolder.send_task_start_date.setText(taskJson
							.optString("starttime"));
				}
				if (taskJson.has("endtime")) {
					sendOATaskViewHolder.send_task_end_date.setText(taskJson
							.optString("endtime"));
				}
				if (taskJson.has("priority")) {
					int priority = taskJson.optInt("priority");
					if (priority == 1) {
						sendOATaskViewHolder.send_task_grade
								.setText(R.string.task_normal);
						sendOATaskViewHolder.send_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_main_color_normal));
					} else if (priority == 2) {
						sendOATaskViewHolder.send_task_grade
								.setText(R.string.task_important);
						sendOATaskViewHolder.send_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_blue_dark));
					} else if (priority == 3) {
						sendOATaskViewHolder.send_task_grade
								.setText(R.string.task_urgent);
						sendOATaskViewHolder.send_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_red));
					} else if (priority == 4) {
						sendOATaskViewHolder.send_task_grade
								.setText(R.string.task_urgent_important);
						sendOATaskViewHolder.send_task_grade
								.setTextColor(mContext.getResources().getColor(
										R.color.the_color_red));
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 显示GIF
	 *
	 * @param mContext
	 * @param webView
	 * @param qyxMsg
	 */
	public static void showGifImage(Context mContext,
			final GifImageView webView, final QyxMsg qyxMsg) {
		// AssetManager am = mMessageListActivity.getResources().getAssets();
		// webView.setVisibility(View.GONE);
		String path = "";
		// webView.setImageResource(mContext.getResources().getColor(R.color.transparent));
		try {
			// InputStream is = am.open(path);
			// is.close();
			// getMinimumHeight
			// path = qyxMsg.content;
			MsgGifModel msgGifModel = (MsgGifModel) qyxMsg.baseContentModel;

			if (!TextUtils.isEmpty(msgGifModel.getFileHash())
					&& !TextUtils.isEmpty(msgGifModel.getFileId())) {
				path = APIConfiguration.getFileDownloadPath(
						msgGifModel.getFileId(), msgGifModel.getFileHash());
			} else {
				path = msgGifModel.getGifName();
			}

			GifDrawable oldGifDrawable = (GifDrawable) webView.getDrawable();
			if (path.indexOf("fileid") > -1 && path.indexOf("filehash") > -1) {
				boolean isExists = HttpStreamCache.getInstance().CheckIsExists(
						path);
				if (isExists) {
					String tempPath = HttpStreamCache.getInstance()
							.GetFilePath(path);
					GifDrawable gifDrawable = new GifDrawable(tempPath);
					webView.setImageDrawable(gifDrawable);
					// webView.setVisibility(View.VISIBLE);
					if (oldGifDrawable != null && !oldGifDrawable.isRecycled()) {
						oldGifDrawable.recycle();
					}
				} else {
					downloadGifByFilePath(path, webView);
				}
			} else {
				GifDrawable gifDrawable = new GifDrawable(mContext
						.getResources().getAssets(), "yutumei/" + path);
				webView.setImageDrawable(gifDrawable);
				// webView.setVisibility(View.VISIBLE);
				if (oldGifDrawable != null && !oldGifDrawable.isRecycled()) {
					oldGifDrawable.recycle();
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
			downloadGifByFilePath(path, webView);
		}
	}

	/**
	 * 下载GIF
	 *
	 * @param path
	 * @param webView
	 */
	private static void downloadGifByFilePath(String path,
			final GifImageView webView) {
		FileUtils mFileUtils = new FileUtils();
		File file = mFileUtils.getFile(path, "gif");
		if (file.exists() && file.length() > 0) {
			try {
				webView.setImageDrawable(new GifDrawable(file.getAbsolutePath()));
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else {
			downloadGif(new IDownloadListener() {
				@Override
				public void OnDownloadSuccess(String face_path) {
					try {
						GifDrawable oldGifDrawable = (GifDrawable) webView.getDrawable();
						webView.setImageDrawable(new GifDrawable(face_path));
						if (oldGifDrawable != null
								&& !oldGifDrawable.isRecycled()) {
							oldGifDrawable.recycle();
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}, path);
		}

	}

	/**
	 * 下载gif动态图
	 *
	 * @param gifListener
	 *            回调接口
	 * @param path
	 *            gif路径
	 */
	private static void downloadGif(final IDownloadListener gifListener,
			final String path) {
		if (!TextUtils.isEmpty(path)) {
			DownloadGifTask mDownloadGifTask = new DownloadGifTask(path,
					gifListener);
			mDownloadGifTask.execute();
		}
	}

	/**
	 * 下载本地没有的gif表情
	 *
	 * @author SL
	 *
	 */
	private static class DownloadGifTask extends AsyncTask<Void, Void, Void> {
		private IDownloadListener gifListener;
		private String face_path;
		private FileUtils fileUtils = null;
		private String path;

		public DownloadGifTask(String _path, IDownloadListener _gifListener) {
			this.gifListener = _gifListener;
			path = _path;
			fileUtils = new FileUtils(IMApplication.appName);
		}

		@Override
		protected Void doInBackground(Void... arg0) {
			face_path = fileUtils.downloadFile1(path, "gif", null, null);
			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			gifListener.OnDownloadSuccess(face_path);
		}
	}

	/**
	 * group背景点击事件
	 *
	 * @param mContext
	 * @param message
	 * @param messageListHelper
	 * @param _msgList
	 */
	public static void onGroupOnClick(Context mContext, QyxMsg message,
			ChatMsgManage messageListHelper, ArrayList<QyxMsgView> _msgList) {
		/**
		 * 图片查看大图
		 */
		if (Integer.valueOf(message.msg_content_type) == MsgContentType.PIC) {
			MsgImageModel imageModel = (MsgImageModel) message.baseContentModel;
			AttachModel attachModel = (AttachModel) imageModel
					.getAttachmentModel();
			String bigpath = "";
			if (!TextUtils.isEmpty(attachModel.getFileLocalPath())) {
				bigpath = attachModel.getFileLocalPath();
			} else if (!TextUtils.isEmpty(attachModel.getFileId())
					&& !TextUtils.isEmpty(attachModel.getFileHash())) {
				bigpath = APIConfiguration.getFileDownloadPath(
						attachModel.getFileId(), attachModel.getFileHash());
			} else {
				return;
			}
			ArrayList<String> strs = messageListHelper.getMsgPicPaths(_msgList);
			Intent show = new Intent(mContext, PictureShowActivity.class);
			show.putExtra("content", bigpath);
			show.putStringArrayListExtra("imgList", strs);
			mContext.startActivity(show);
		} else if (Integer.valueOf(message.msg_content_type) == MsgContentType.LOCATION) {
			/** 查看位置 **/
			MsgLocationModel locationModel = (MsgLocationModel) message.baseContentModel;
			Bundle bu = new Bundle();
			bu.putString("mineLat", locationModel.getLatitude());
			bu.putString("mineLng", locationModel.getLongitude());
			Utils.startActivity(mContext, LocationNavigationActivity.class, bu);
		} else if (Integer.valueOf(message.msg_content_type) == MsgContentType.FILE) {
			/** 查看文件 **/
			Intent intent = new Intent();
			Bundle mBundle = new Bundle();
			mBundle.putParcelable("mQyxMsg", message);
			intent.putExtras(mBundle);
			intent.setClass(mContext, DownloadFileActivity.class);
			mContext.startActivity(intent);
		} else if (message.msg_content_type == MsgContentType.BUSINESS_CRAD) {
			/** 查看名片 **/
			MsgCradModel msgCradModel = (MsgCradModel) message.baseContentModel;
			if (!TextUtils.isEmpty(msgCradModel.getCustId())) {
				if (msgCradModel.getCradType() == BusinessCradType.PUBLIC_NUM_CRAD) {
					Bundle bundle = new Bundle();
					bundle.putString("cust_id", msgCradModel.getCustId());
					ActivityHandle.startActivity((Activity) mContext,
							PublicNumberDetailActivity.class, bundle, -1);
				} else {
					ActivityHandle.startUserDetailActivity((Activity) mContext,
							msgCradModel.getCustId());
				}
			}

		} else if (message.msg_content_type == MsgContentType.RED) {
			/** 查看红包 **/
			boolean isToDetail = false;
			MsgRedModel msgRedModel = (MsgRedModel) message.baseContentModel;
			if (message.from_cust_id == Long
					.valueOf(IMApplication.getCustId())
					&& message.sessionModel.getSessionType() == PacketType.PERSONAL) {
				isToDetail = true;
			}
			messageListHelper.getRed(msgRedModel.getPacketsid(), isToDetail);

		} else if (message.msg_content_type == MsgContentType.TRANSFER_ACCOUNTS) {
			/** 转账 **/
			MsgTransferModel msgTransferModel = (MsgTransferModel) message.baseContentModel;
			if (msgTransferModel != null) {
				Intent intent = new Intent();
				intent.putExtra("turnoverid", msgTransferModel.getTurnoverid());
				intent.setClass(mContext, TransferDetailActivity.class);
				mContext.startActivity(intent);
			}
		} else if (message.msg_content_type == MsgContentType.CROWD_FUND) {
			/** 众筹(江湖救急) **/
			MsgCrowdFundsModel crowdFundsModel = (MsgCrowdFundsModel) message.baseContentModel;
			if (crowdFundsModel != null) {
				Intent intent = new Intent(mContext, CrowdFundDetailActivity.class);
				intent.putExtra("fundid", crowdFundsModel.getFundId());
				mContext.startActivity(intent);
			}
		} else if (message.msg_content_type == MsgContentType.VIDEO) {
			/**视频**/
			MsgVideoModel msgVideoModel = (MsgVideoModel) message.baseContentModel;
			if (msgVideoModel != null) {
				AttachModel attachModel = (AttachModel) msgVideoModel
						.getAttachmentModel();
				Intent intent = new Intent(mContext, VideoPlayerActivity.class);
				String path = attachModel.getFileLocalPath();
				if (TextUtils.isEmpty(attachModel.getFileLocalPath())) {
					//下载视频
					path = APIConfiguration.getFileDownloadPath(attachModel.getFileId(),attachModel.getFileHash());
					intent.putExtra("mQyxMsg",message);
				}
				intent.putExtra("path", path);
				intent.putExtra("width", msgVideoModel.getScreeHostW());
				intent.putExtra("height", msgVideoModel.getScreeHostH());
				mContext.startActivity(intent);
			}
		} else if (message.msg_content_type == MsgContentType.ACCEPT_JOIN_ORG) {
			/** 邀请加入群聊 **/
			if (!TextUtils.isEmpty(message.content_json)) {
				try {
					JSONObject json = new JSONObject(message.content_json);
					if (json != null && json.has("chatid")
							&& json.has("contributid")) {
						String chatid = json.optString("chatid");
						String contributid = json.optString("contributid");
						Intent intent = new Intent(mContext,
								InvitJoinGroupDetailActivity.class);
						intent.putExtra("chatid", chatid);
						intent.putExtra("contributid", contributid);
						intent.putExtra("invitecustid", message.from_cust_id
								+ "");
						mContext.startActivity(intent);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		} else if (message.msg_content_type == 10002) {
			/** 催缴经费 **/
			if (!TextUtils.isEmpty(message.content_json)) {
				try {
					JSONObject json = new JSONObject(message.content_json);
					if (json != null && json.has("chatid")) {
						String chatid = json.optString("chatid");
						Intent intent = new Intent(mContext,
								FundsManageActivity.class);
						intent.putExtra("selected_type", 1);
						intent.putExtra("chat_id", chatid);
						mContext.startActivity(intent);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		} else if (message.msg_content_type == MsgContentType.OA_APPROVAL
				|| message.msg_content_type == MsgContentType.OA_REIMBURSEMENT
				|| message.msg_content_type == MsgContentType.OA_NOTICE
				|| message.msg_content_type == MsgContentType.OA_TASK) {
			try {
				/** OA办公打开网页 **/
				JSONObject contentJson = new JSONObject(message.content);
				String url = contentJson.optString("url");
				Intent intent = new Intent();
				intent.putExtra("url", url);
				intent.setClass(mContext, OaWebViewActivity.class);
				mContext.startActivity(intent);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

	}

	/**
	 * 显示新闻数据
	 * @param mLongClickListener
	 * @param msgView
	 * @param mContext
	 * @param newsLinearLayout
	 */
	public static void showNewsMsg(OnLongClickListener mLongClickListener,
			QyxMsgView msgView, Context mContext, LinearLayout newsLinearLayout) {
		if (msgView.msg == null || newsLinearLayout == null)
			return;
		if (!TextUtils.isEmpty(msgView.msg.content)) {
			try {
				JSONObject jsonObject = new JSONObject(msgView.msg.content);
				if (jsonObject != null && jsonObject.has("itemscontent")) {
					JSONArray jsonArray = jsonObject
							.optJSONArray("itemscontent");
					if (jsonArray != null && jsonArray.length() > 0) {
						getNewsItemView(mLongClickListener, msgView, mContext,
								newsLinearLayout, jsonArray);
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 获取新闻布局
	 *
	 * @param mLongClickListener
	 * @param msgView
	 * @param mContext
	 * @param newsLinearLayout
	 * @param jsonArray
	 */
	private static void getNewsItemView(
			final OnLongClickListener mLongClickListener, QyxMsgView msgView,
			final Context mContext, LinearLayout newsLinearLayout,
			JSONArray jsonArray) {
		if (jsonArray == null || jsonArray.length() < 1
				|| newsLinearLayout == null) {
			return;
		}
		ArrayList<NewsEntity> arrayList = NewsEntity.serNewsEntitys(jsonArray);
		if (arrayList != null && arrayList.size() > 0) {
			newsLinearLayout.removeAllViews();
			setNewsTopView(mLongClickListener, msgView, mContext,
					newsLinearLayout, arrayList.get(0));
			for (int i = 1, size = arrayList.size(); i < size; i++) {
				final NewsEntity mNewsEntity = arrayList.get(i);
				View contentView = View.inflate(mContext,
						R.layout.item_news_layout, null);
				TextView titleTv = (TextView) contentView
						.findViewById(R.id.news_item_tv);
				MaskImageView avatarIv = (MaskImageView) contentView
						.findViewById(R.id.news_item_iv);
				titleTv.setText(mNewsEntity.thumtitle);
				if (!TextUtils.isEmpty(mNewsEntity.thumimg)) {
					JSONObject json;
					try {
						json = new JSONObject(arrayList.get(i).thumimg);
						String file_id = json.optString("fileid");
						String file_hash = json.optString("filehash");
						avatarIv.SetUrl(APIConfiguration
								.getFileSmallDownloadPath(file_id, file_hash));
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
				contentView.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						if (!TextUtils.isEmpty(mNewsEntity.url)) {
							String url = mNewsEntity.url
									+ APIConfiguration.getCustIdAndToken();
							Intent mIntent = new Intent(mContext,
									OaWebViewActivity.class);
							mIntent.putExtra("url", url);
							mContext.startActivity(mIntent);
						}
					}
				});
				contentView.setTag(msgView);
				contentView.setOnLongClickListener(mLongClickListener);
				newsLinearLayout.addView(contentView);
			}
		} else {

		}

	}

	/**
	 * 添加新闻头
	 *
	 * @param mLongClickListener
	 * @param msgView
	 * @param mContext
	 * @param newsLinearLayout
	 * @param mNewsEntity
	 */
	private static void setNewsTopView(
			final OnLongClickListener mLongClickListener,
			final QyxMsgView msgView, final Context mContext,
			LinearLayout newsLinearLayout, final NewsEntity mNewsEntity) {
		View contentView = View.inflate(mContext,
				R.layout.item_news_top_layout, null);
		TextView titleTv = (TextView) contentView
				.findViewById(R.id.news_top_title_tv);
		MaskImageView avatarIv = (MaskImageView) contentView
				.findViewById(R.id.news_top_iv);
		titleTv.setText(mNewsEntity.thumtitle);
		if (!TextUtils.isEmpty(mNewsEntity.bannerimg)) {
			JSONObject json;
			try {
				json = new JSONObject(mNewsEntity.bannerimg);
				String file_id = json.optString("fileid");
				String file_hash = json.optString("filehash");
				avatarIv.SetUrl(APIConfiguration.getFileDownloadBySize(file_id,
						file_hash, 600, 300));
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		contentView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				if (!TextUtils.isEmpty(mNewsEntity.url)) {
					String url = mNewsEntity.url + APIConfiguration.getCustIdAndToken();
					Intent mIntent = new Intent(mContext,
							OaWebViewActivity.class);
					mIntent.putExtra("url", url);
					mContext.startActivity(mIntent);
				}
			}
		});
		contentView.setTag(msgView);
		contentView.setOnLongClickListener(mLongClickListener);
		newsLinearLayout.addView(contentView);
	}

}
